$(function () {
  layui.use('laydate', function(){
    var laydate = layui.laydate;
    
    //执行一个laydate实例
    laydate.render({
      elem: '#layd' //指定元素
    })
  })

  $('.add-exam #subjectinfo .subject').on('click', function() {
    layui.use("layer",function(){
      layer.open({
        type: 1,
        title: '选择科目',
        content: $('#select-subject'),
        offset: '30px',
        area: ['800px', '600px']
      })
    })

    renderSubjectTable()
  })

  function renderSubjectTable() {
    layui.use('table', function () {
      var table = layui.table
      table.render({
        elem: '#subject-table',
        url: '/Do/MS/queryMsBatchFileJson?' + $("#positionSearchbox").serialize(), //数据接口
        page: true,
        cols: [
          [
            { field: 'topicName', title: '科目名称', width: 360 },
            { field: 'name', title: '创建人', width: 150 },
            { field: 'time', title: '创建时间', width: 200 },
            { field: 'oprate', title: '选择', width: 80 },
          ],
        ],
      })
    })
  }

  $('.add-exam #subjectinfo .test').on('click', function() {
    layui.use("layer",function(){
      layer.open({
        type: 1,
        title: '选择试卷',
        content: $('#select-test'),
        offset: '30px',
        area: ['800px', '600px']
      })
    })

    renderTestTable()
  })

  function renderTestTable() {
    layui.use('table', function () {
      var table = layui.table
      table.render({
        elem: '#test-table',
        url: '/Do/MS/queryMsBatchFileJson?' + $("#positionSearchbox").serialize(), //数据接口
        page: true,
        cols: [
          [
            { field: 'testName', title: '试卷名称', width: 710 },
            { field: 'oprate', title: '选择', width: 80 },
          ],
        ],
      })
    })
  }
})
